/**

 */

/**
 * @fileoverview Blocks for Min.
 * @author huunam0@gmail.com (Nam Tran)
 */
'use strict';


Blockly.JavaScript = Blockly.Generator.get('JavaScript');



/**
 * 'Set seat' block.
 * @type Blockly.BlocK
 */
var seatsBlock = null;
var maxBlocks = window.parent.maxBlocks;
/**
 * Initialize Blockly and the SVG.
 */
function init() {
  var toolbox = document.getElementById('toolbox');
  Blockly.inject(document.getElementById('svgDiv'),
                 {path: '../../', maxBlocks: maxBlocks, toolbox: toolbox});

  // Load the editor with a starting block.
  var xml = Blockly.Xml.textToDom(
      '<xml>' +
      '  <block type="viet_ra" x="220" y="50"></block>' +
      '</xml>');
  Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml);
  seatsBlock = Blockly.mainWorkspace.getTopBlocks(false)[0];

  Blockly.addChangeListener(recalculate);

  //window.onbeforeunload = function() {
  //  return 'Leaving this page will result in the loss of your work.';
  //};
}

/**
 * Use the blocks to calculate the number of seats.
 * Display the calculated number.
 */
function recalculate() {
  
  var generator = Blockly.Generator.get('JavaScript');
  generator.init();
  var code = generator.blockToCode(seatsBlock);
  //alert(code);
  document.getElementById("thongbao").innerHTML="."+code;
  //document.getElementById('seatYes');
  
}

